<template>
  <div class="player-card" :class="{ 'current-user': isCurrentUser, 'host': isHost }">
    <div class="avatar-container">
      <img :src="player.avatar || defaultAvatar" :alt="player.username" class="avatar">
      <span class="online-status" :class="{ 'online': player.isOnline }"></span>
    </div>

    <div class="player-info">
      <span class="username">{{ player.username }}</span>
      <div class="badges">
        <span v-if="player.status === 'host'" class="host-badge">房主</span>
        <span v-if="player.id === useUserStore().userId" class="you-badge">你</span>
      </div>
    </div>

    <div class="player-stats">
      <span class="stat">胜率: {{ player.winRate || '--' }}%</span>
      <span class="stat">场次: {{ player.playCount || 0 }}</span>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {useUserStore} from "@/stores/user.js";

const props = defineProps({
  player: {
    type: Object,
    required: true
  },
  isCurrentUser: {
    type: Boolean,
    default: false
  },
  isHost: {
    type: Boolean,
    default: false
  }
})

const defaultAvatar = ref('https://img.tukuppt.com/png_preview/00/52/31/gqsUON6GeI.jpg!/fw/780')


</script>

<style scoped>
.player-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.player-card:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-3px);
}

.player-card.current-user {
  border-color: #4cc9f0;
}

.player-card.host {
  border-color: #6a11cb;
}

.avatar-container {
  position: relative;
  width: 50px;
  height: 50px;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #4cc9f0;
}

.online-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #6c757d;
  border: 2px solid #1a1a2e;
}

.online-status.online {
  background-color: #4cc9f0;
}

.player-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.username {
  font-weight: 500;
  font-size: 1rem;
  margin-bottom: 5px;
}

.badges {
  display: flex;
  gap: 5px;
}

.host-badge, .you-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.host-badge {
  background: #6a11cb;
  color: white;
}

.you-badge {
  background: #4cc9f0;
  color: white;
}

.player-stats {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
}
</style>